<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
<!--      <a-form layout="inline" @keyup.enter.native="searchQuery">-->
<!--        <a-row :gutter="24">-->
<!--          &lt;!&ndash; 查询按钮 &ndash;&gt;-->
<!--          <a-col :offset='8'>-->
<!--            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>-->
<!--              <a-button type='primary' @click='xkwlogin' icon='search'>登录</a-button>-->
<!--              <a-button type='primary' @click='xkwauthentication' icon='reload' style='margin-left: 8px'>验证</a-button>-->
<!--&lt;!&ndash;              <a-button type='primary' @click='xkwlogin2' icon='search'>登录2</a-button>&ndash;&gt;-->
<!--&lt;!&ndash;              <a-button type='primary' @click='xkwauthentication2' icon='reload' style='margin-left: 8px'>验证2</a-button>&ndash;&gt;-->
<!--              <a @click='handleToggleSearch' style='margin-left: 8px'>-->
<!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
<!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />-->
<!--              </a>-->
<!--            </span>-->
<!--          </a-col>-->
<!--        </a-row>-->
<!--      </a-form>-->
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->


    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <label >使用学科网资源需绑定学科网账号信息！</label>
<!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
<!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
      </div>
      <iframe :id='id' :src='this.url.redirectUrl' frameborder='0' width='100%' height='800px' scrolling='auto'></iframe>


    </div>

  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction, postAction } from '@api/manage'
  import Vue from 'vue'
  import { ACCESS_TOKEN, YEAR_SEMESTER } from '@/store/mutation-types'

  export default {
    name: 'xkwoauth',
    mixins:[JeecgListMixin, mixinDevice],
    components: {

    },
    data () {
      return {
        description: '学科网注册管理页面',
        id: '',
        url: {
          // list: "/oauth/xkwoauth/xkwLoginController",
          xkwlogin: "/oauth/xkwoauth/xkwLoginController/login",
          xkwauthentication: "/oauth/xkwoauth/oauthClientController/authentication",
          redirectUrl: ""



        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.xkwauthentication();//绑定学科网
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'gradeCode',text:'年级编码'})
        fieldList.push({type:'string',value:'gradeName',text:'年级名称'})
        fieldList.push({type:'string',value:'tenantId',text:'学校编码'})
        fieldList.push({type:'int',value:'gradeStage',text:'年级阶段'})
        fieldList.push({type:'string',value:'gradeNextCode',text:'下一年级编码'})
        fieldList.push({type:'int',value:'gradeOrder',text:'排序'})
        this.superFieldList = fieldList
      },
      searchQuery(){},
      loadData(){},
      xkwlogin(){
        let params = {}
        postAction(this.url.xkwlogin,params).then((res) => {
          if (res.success){
            this.$message.success(res.message)
          }else {
            this.$message.error(res.message)
          }
        });

      },

      xkwauthentication(){
        let token = Vue.ls.get(ACCESS_TOKEN)
        var params = {smartschoolToken: token}//查询条件

        getAction(this.url.xkwauthentication, params).then((res) => {
          console.log('------res------' + res)
          if (res.success) {
            let redirectUrl2 = res.result.redirect

            this.url.redirectUrl=redirectUrl2+"&smartschoolToken="+token
            console.log('------xkwauthentication:redirectUrl2------' + redirectUrl2)
            this.getredirectUrl(redirectUrl2)
          } else {
            this.$message.warning(res.message)
          }
        })
      },
      closeCurrent(){
        this.remove(this.activePage);
      },
      getredirectUrl(redirectUrl){
        console.log('------getredirectUrl:redirectUrl------' + redirectUrl)
        //url支持通过 ${token}方式传递当前登录TOKEN
        let tokenStr = '${token}'
        let schoolYearIdStr = '${schoolYearId}'
        let semesterIdStr = "${semesterId}";
        if (redirectUrl.indexOf(tokenStr) != -1 ) {
          let token = Vue.ls.get(ACCESS_TOKEN)
          let schoolYearId = Vue.ls.get(YEAR_SEMESTER).schoolYearId
          let semesterId = Vue.ls.get(YEAR_SEMESTER).semesterId
          redirectUrl = redirectUrl.replace(tokenStr, token).replace(schoolYearIdStr, schoolYearId).replace(semesterIdStr, semesterId);
        }
        else if ( redirectUrl.indexOf("#{token}") != -1) {
          let token = Vue.ls.get(ACCESS_TOKEN)
          let schoolYearId = Vue.ls.get(YEAR_SEMESTER).schoolYearId
          let semesterId = Vue.ls.get(YEAR_SEMESTER).semesterId
          redirectUrl = redirectUrl.replace("#{token}", token).replace(schoolYearIdStr, schoolYearId).replace(semesterIdStr, semesterId);
        } else {
          redirectUrl = redirectUrl+"&token="+Vue.ls.get(ACCESS_TOKEN)
        }

        var params = {token:Vue.ls.get(ACCESS_TOKEN)}//查询条件
        getAction(redirectUrl, params).then((res) => {
          if (res.success) {
            this.url.redirectUrl = res.result.redirect
            console.log('------this.url.redirectUrl------' + this.url.redirectUrl)
            this.goUrl(this.url.redirectUrl)
          } else {
            this.$message.warning(res.message)
          }
        })
      },
      goUrl(redirectUrl) {
        let url = this.$route.meta.url
        let id = this.$route.path
        this.id = id
        //url = "http://www.baidu.com"
        console.log('------id------' + id)
        console.log('------url------' + url)
        console.log('------redirectUrl------' + redirectUrl)
        if (redirectUrl !== null && redirectUrl !== undefined) {
          // this.closeCurrent()
          // this.$router.push({name: "/学科网", params: {id: redirectUrl}}) //新窗口打开页面

          // window.open(redirectUrl, "_blank")
          // window.open(redirectUrl, "_blank") //新窗口打开页面
          //-----------------------------------------------------------------------------------------
          //url支持通过 ${token}方式传递当前登录TOKEN
          // let tokenStr = '${token}'
          // let schoolYearIdStr = '${schoolYearId}'
          // let semesterIdStr = "${semesterId}";
          // if (url.indexOf(tokenStr) != -1) {
          //   let token = Vue.ls.get(ACCESS_TOKEN)
          //   let schoolYearId = Vue.ls.get(YEAR_SEMESTER).schoolYearId
          //   let semesterId = Vue.ls.get(YEAR_SEMESTER).semesterId
          //   this.url = url.replace(tokenStr, token).replace(schoolYearIdStr, schoolYearId).replace(semesterIdStr, semesterId);
          // } else {
          //   this.url = url
          // }
          //-----------------------------------------------------------------------------------------

          /*update_begin author:wuxianquan date:20190908 for:判断打开方式，新窗口打开时this.$route.meta.internalOrExternal==true */
          // if (this.$route.meta.internalOrExternal != undefined && this.$route.meta.internalOrExternal == true) {
          //   this.closeCurrent()
          //   window.open(redirectUrl)
          // }
          /*update_end author:wuxianquan date:20190908 for:判断打开方式，新窗口打开时this.$route.meta.internalOrExternal==true */

        }
      }


    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>